const app = getApp();
const http = require('../../../utils/http.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    storeList: [],
    customer:null,
    txtString:''
  },
  inputClick:function(e){
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      txtString: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      customer: app.globalData.customer
    })
    if(options.itemName){
      this.setData({
        itemName: options.itemName
      })
    }
    if(options.txtString){
      this.setData({
        txtString: options.txtString
      })
      this.search(options.txtString);
    }else{
      this.search('');
    }
  },
  search:function(txtString){
    let data
    if(this.data.txtString){
      data = {name:this.data.txtString}
    }else{
      data = {name:''}
    }
    if (txtString && !txtString.type) {
      data = {name:txtString}
    }
    console.log(txtString)
    
    http.get('/api/index/searchStore', data).then(res => {
      if (res.code == 200) {
        this.setData({
          storeList: res.data
        })
        if(res.data.length<1){
          wx.showToast({
            title:'暂时没有你要搜索的商品',
            icon:'none'
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

})
